home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / imengv3.41p2.lha / ImEngV3.41p2 / Extra / ARexx / IndexChange.rexx next >
OS/2 REXX Batch file  |  1997-01-06  |  2KB  |  66 lines

  1. /*
  2. ** $VER: IndexChange.rexx 1.05 (4/1 Stockholm/Sweden)
  3. ** Copyright © 1997 by Patrik M Nydensten 
  4. **
  5. ** Changes the index number for files.
  6. ** The new name will be the old basename but with another index number.
  7. ** The index number can be added or subtracted with a specified number.
  8. ** A positive number adds while a negative number subtracts.
  9. **
  10. ** Usage: <add/sub_number> <first_index_file> <last_index_file>
  11. */
  12.  
  13. options results
  14.  
  15. parse arg num files
  16. if pos('"',files) = 0 then parse var files file1 file2
  17. else parse var files '"'file1'"' '"'file2'"'
  18.  
  19. number = strip(num)
  20. if ~datatype(number,'N') then errorx('Error: Bad add/sub number.')
  21.  
  22. fix = strip(get_ext(file1)) ; lix = strip(get_ext(file2))
  23. if ((~datatype(fix,'N'))|(~datatype(lix,'N'))) then errorx('Error: Bad index number in file name.')
  24. fi = min(fix,lix) ; li = max(fix,lix)
  25.  
  26. if (fi+number) < 1 then errorx('Error: Add/sub number below 1.')
  27. do i = fi to li
  28.   new_file = get_base(file1)'.'right(i+number,4,'0')
  29.   old_file = get_base(file1)'.'right(i,4,'0')
  30.   if exists(old_file) then do
  31.     address 'COMMAND' 'rename' '"'old_file'"' '"'new_file'!"'
  32.   end
  33.   else say 'Error: Could not locate file "'old_file'".'
  34. end
  35.  
  36. do i = fi to li
  37.   new_file = get_base(file1)'.'right(i+number,4,'0')
  38.   if exists(new_file'!') then do
  39.     if ~exists(new_file) then address 'COMMAND' 'rename' '"'new_file'!"' '"'new_file'"'
  40.     else say 'Error: An image with that name already exist!'d2c(10)||,
  41.              '       File: "'new_file'"'
  42.   end
  43. end
  44.  
  45. exit
  46.  
  47. /* --[ proc ]--------------------------- */
  48.  
  49. errorx:
  50.   parse arg text
  51.   say text
  52.   exit 5
  53. return 0
  54.  
  55. get_ext:
  56.   parse arg get_ext_in
  57.   if lastpos('.',get_ext_in) ~= 0 then get_ext_back = substr(get_ext_in,1+lastpos('.',get_ext_in))
  58.   else get_ext_back = ''
  59. return get_ext_back
  60.  
  61. get_base:
  62.   parse arg get_base_in
  63.   if lastpos('.',get_base_in) ~= 0 then get_base_back = substr(get_base_in,1,lastpos('.',get_base_in)-1)
  64.   else get_base_back = get_base_in
  65. return get_base_back
  66.